package zzj.campus_book_sharing_platform.Controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zzj.campus_book_sharing_platform.Entity.Answer;
import zzj.campus_book_sharing_platform.Service.impl.AnswerServiceImpl;
import zzj.campus_book_sharing_platform.uitl.ResultFormat;
import zzj.campus_book_sharing_platform.uitl.ResultUtil;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Tag(name = "帖子回复")
@RestController
@RequestMapping("/answer")
public class answerController {
    @Resource
    AnswerServiceImpl answerService;
    /**
     * 帖子回复的插入操作
     *
     * @param answer
     * @param postId
     * @param session
     * @return
     */
    @GetMapping("/insert")
    @Operation(summary = "发布回复消息")
    public ResultFormat insertAnswer(String answer ,String postId, HttpSession session){
        return ResultUtil.success(answerService.insert(answer ,postId, session));
    }

    /**
     * 帖子回复的删除操作,分为用户自己删和管理员删除
     *
     * @param answerId
     * @param session
     * @return
     */
    @Operation(summary = "删除回复消息")
    @GetMapping("/delete")
    public ResultFormat delete(String answerId, HttpSession session){
        return ResultUtil.success(answerService.deleteById(answerId,session));
    }

    /**
     * 一个帖子历史回复的查询操作
     *
     * @param postId
     * @param session
     * @return
     */
    @Operation(summary = "查询帖子回复")
    @GetMapping("/queryAllById")
    public ResultFormat queryAllById(String postId, HttpSession session){
        List<Answer> answer = answerService.queryAllById(postId, session);
        return ResultUtil.success(answerService.queryAllById(postId, session));
    }
}
